<?php

function createThumb($sourceimg, $preferedSize){
$file_ext =  filetype($sourceimg);
$mainImage = imagecreatefromjpeg($sourceimg);

$mainWidth = imagesx($mainImage);
$mainHeight = imagesy ($mainImage) ;
if($mainWidth<$preferedSize || $mainHeight <$preferedSize)
{
	$thumbWidth = $mainWidth;
	$thumbHeight = $mainHeight;
}else { 
	
	$thumbHeight = $preferedSize;
	$thumbWidth = intval(($mainWidth *$preferedSize) /$mainHeight);
}
$myThumbnail = imagecreatetruecolor($thumbWidth, $thumbHeight);

imagecopyresampled($myThumbnail, $mainImage, 0, 0,0,0, $thumbWidth,$thumbHeight, $mainWidth, $mainHeight);
return  $myThumbnail;

}
header("Content-type: image/jpeg");
$folder = $_GET['f'];
$image = $_GET['im'];
$th = createThumb($image, $size);
imagejpeg ($th);
imagedestroy ($th);

?>

